const http=require('http');
const fs=require('fs');
const path=require('path');

http.createServer((req,res)=>{
    if(req.url.indexOf('/detail')>=0){
        var filePath=path.join(__dirname,'/chapter.html');
        var fileContent=fs.readFileSync(filePath);
        res.writeHead(200,{'Content-Type':'text/html'});
        res.write(fileContent);
        res.end();
    }else if(req.url.indexOf('css/')>=0){
        var filePath=path.join(__dirname,'/'+req.url);
        var fileContent=fs.readFileSync(filePath);
        res.writeHead(200,{'Content-Type':'text/css'});
        res.write(fileContent);
        res.end();
    }else if(req.url.indexOf('/baiduTemplate.js')>=0){
        var filePath=path.join(__dirname,'/js/baiduTemplate.js');
        var fileContent=fs.readFileSync(filePath);
        res.writeHead(200,{"Content-type":'text/js'});
        res.write(fileContent);
        res.end();
    }else if(req.url.indexOf('images/')>=0){
        var imgPath=path.join(__dirname,'/'+req.url);
        var imgContent=fs.readFileSync(imgPath);
        res.writeHead(200,{"Content-Type":'image/jpg'});
        res.write(imgContent);
        res.end();
    }
}).listen(8083)